bitkeeper revision 1.747 (403b7cf86JDQU8_ljAm9SqJGvsVF4w)
authormwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Tue, 24 Feb 2004 16:34:00 +0000 (16:34 +0000)
committermwilli2@equilibrium.research.intel-research.net <mwilli2@equilibrium.research.intel-research.net>
Tue, 24 Feb 2004 16:34:00 +0000 (16:34 +0000)
Physical hardware info dom0 op.

.rootkeys
tools/examples/xc_physinfo.py [new file with mode: 0644]
tools/xc/lib/xc.h
tools/xc/lib/xc_misc.c
tools/xc/py/Xc.c
xen/common/dom0_ops.c
xen/include/hypervisor-ifs/dom0_ops.h

index cd0b234a42cd3297908714da23e778c31a99dad9..788428d145f67fa875a1970c2ca16f214c55254e 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
@@ -48,6 +48,7 @@
 40278d91ZjLhxdjjrGe8HEdwHLj5xQ tools/examples/netbsd
 401d7e16NpnVrFSsR7lKKKfTwCYvWA tools/examples/xc_dom_control.py
 401d7e16RJj-lbtsVEjua6HYAIiKiA tools/examples/xc_dom_create.py
+403b7cf7J7FsSSoEPGhx6gXR4pIdZg tools/examples/xc_physinfo.py
 401d7e16X4iojyKopo_j63AyzYZd2A tools/examples/xc_vd_tool.py
 40278d94cIUWl2eRgnwZtr4hTyWT1Q tools/examples/xendomains
 3f776bd2Xd-dUcPKlPN2vG89VGtfvQ tools/misc/Makefile
diff --git a/tools/examples/xc_physinfo.py b/tools/examples/xc_physinfo.py
new file mode 100644 (file)
index 0000000..0d9db79
--- /dev/null
@@ -0,0 +1,20 @@
+#!/usr/bin/env python
+
+# Get information about the physical host machine
+
+import Xc
+
+xc = Xc.new()
+
+info = xc.physinfo()
+
+fmt_info = [ ( 'CPU cores', info['cores']),
+             ('Hyperthreads per core', info['ht_per_core']),
+             ('CPU Speed (MHz)', info['cpu_khz'] / 1000),
+             ('Total physical mem (MB)', info['total_pages'] / 256),
+             ('Free physical mem (MB)', info['free_pages'] / 256) ]
+      
+
+for (item, val) in fmt_info:
+    print "%-23s" % item, ':', val
+
index 5959c6265a2288a6cdcf9dfbb1d4cab92453af7f..74a4fca2ed2f2a002e167969119c476e8564b5c3 100644 (file)
@@ -118,6 +118,14 @@ typedef struct {
     u64            nr_sectors;
 } xc_vbdextent_t;
 
+typedef struct {
+    int ht_per_core;
+    int cores;
+    unsigned long total_pages;
+    unsigned long free_pages;
+    unsigned long cpu_khz;
+} xc_physinfo_t;
+
 int xc_vbd_create(int xc_handle,
                   u64 domid, 
                   unsigned short vbdid, 
@@ -153,5 +161,7 @@ int xc_readconsolering(int xc_handle,
                        unsigned int max_chars, 
                        int clear);
 
+int xc_physinfo(int xc_handle,
+               xc_physinfo_t *info);
 
 #endif /* __XC_H__ */
index e4efec4a41206d334cb7dade05c4973cba70872b..63c53146b7f49c91084d433b0fa8af6ff9004c9b 100644 (file)
@@ -46,3 +46,25 @@ int xc_readconsolering(int xc_handle,
     return ret;
 }    
 
+
+int xc_physinfo(int xc_handle,
+               xc_physinfo_t *put_info)
+{
+    int ret;
+    dom0_op_t op;
+    dom0_physinfo_t *got_info = &op.u.physinfo;
+    
+    op.cmd = DOM0_PHYSINFO;
+    op.interface_version = DOM0_INTERFACE_VERSION;
+
+    if((ret = do_dom0_op(xc_handle, &op))) return ret;
+
+    put_info->ht_per_core = got_info->ht_per_core;
+    put_info->cores       = got_info->cores;
+    put_info->total_pages = got_info->total_pages;
+    put_info->free_pages  = got_info->free_pages;
+    put_info->cpu_khz     = got_info->cpu_khz;
+
+    return 0;
+}
+
index e34764b23f2a3935fad4a42287484a0aca2345d6..2376be5eae639a1a7197d8b059c0dc223d2c75f8 100644 (file)
@@ -788,6 +788,34 @@ static PyObject *pyxc_readconsolering(PyObject *self,
     return PyString_FromStringAndSize(str, (ret < 0) ? 0 : ret);
 }
 
+static PyObject *pyxc_physinfo(PyObject *self,
+                              PyObject *args,
+                              PyObject *kwds)
+{
+    XcObject *xc = (XcObject *)self;
+    PyObject *ret_obj;
+    int xc_ret;
+    xc_physinfo_t info;
+    
+    xc_ret = xc_physinfo(xc->xc_handle, &info);
+
+    if(!xc_ret)
+    {
+        ret_obj = Py_BuildValue("{s:i,s:i,s:l,s:l,s:l}",
+                                "ht_per_core", info.ht_per_core,
+                                "cores",       info.cores,
+                                "total_pages", info.total_pages,
+                                "free_pages",  info.free_pages,
+                                "cpu_khz",     info.cpu_khz);
+    }
+    else
+    {
+        ret_obj = Py_BuildValue(""); /* None */
+    }
+    
+    return ret_obj;
+}
+
 static PyMethodDef pyxc_methods[] = {
     { "domain_create", 
       (PyCFunction)pyxc_domain_create, 
@@ -1010,6 +1038,13 @@ static PyMethodDef pyxc_methods[] = {
       " clear [int, 0]: Bool - clear the ring after reading from it?\n\n"
       "Returns: [str] string is empty on failure.\n" },
 
+    { "physinfo",
+      (PyCFunction)pyxc_physinfo,
+      METH_VARARGS, "\n"
+      "Get information about the physical host machine\n"
+      "Returns [dict]: information about the hardware"
+      "        [None]: on failure.\n" },
+
     { NULL, NULL, 0, NULL }
 };
 
index c225dffd3f2f1ce6d466e7eb4b65e26bdbc86b4e..ab81ca662cf1a6ecd2c1ecaf69276a939d3c4296 100644 (file)
@@ -451,8 +451,31 @@ long do_dom0_op(dom0_op_t *u_dom0_op)
                                op->u.readconsole.count,
                                op->u.readconsole.cmd); 
     }
-    break;    
+    break;
+
+    case DOM0_PHYSINFO:
+    {
+        extern int phys_proc_id[];
+        extern unsigned long cpu_khz;
+
+        dom0_physinfo_t *pi = &op->u.physinfo;
+
+        int old_id = phys_proc_id[0];
+        int ht = 0;
+
+        while( ( ht < smp_num_cpus ) && ( phys_proc_id[ht] == old_id ) ) ht++;
 
+        pi->ht_per_core = ht;
+        pi->cores       = smp_num_cpus / pi->ht_per_core;
+        pi->total_pages = max_page;
+        pi->free_pages  = free_pfns;
+        pi->cpu_khz     = cpu_khz;
+
+        copy_to_user(u_dom0_op, op, sizeof(*op));
+        ret = 0;
+    }
+    break;
+    
     default:
         ret = -ENOSYS;
 
index f21c20fbcfd843dec6eef1156941cf183f573781..5e0abe6295a4097145f12f80cf3ae605f89ae2d3 100644 (file)
@@ -17,8 +17,7 @@
  * This makes sure that old versions of dom0 tools will stop working in a
  * well-defined way (rather than crashing the machine, for instance).
  */
-#define DOM0_INTERFACE_VERSION   0xAAAA0006
-
+#define DOM0_INTERFACE_VERSION   0xAAAA0007
 
 /*
  * The following is all CPU context. Note that the i387_ctxt block is filled 
@@ -218,6 +217,19 @@ typedef struct dom0_gettbufs_st
   unsigned long phys_addr;
 } dom0_gettbufs_t;
 
+/*
+ * Get physical information about the host machine
+ */
+#define DOM0_PHYSINFO         22
+typedef struct dom0_physinfo_st
+{
+    int ht_per_core;
+    int cores;
+    unsigned long cpu_khz;
+    unsigned long total_pages;
+    unsigned long free_pages;
+} dom0_physinfo_t;
+
 typedef struct dom0_op_st
 {
     unsigned long cmd;
@@ -241,6 +253,7 @@ typedef struct dom0_op_st
        dom0_readconsole_t      readconsole;
        dom0_pincpudomain_t     pincpudomain;
         dom0_gettbufs_t         gettbufs;
+        dom0_physinfo_t         physinfo;
     } u;
 } dom0_op_t;